import { Component, Inject } from '@angular/core';
import { FormControl, Validators, ValidatorFn, AbstractControl, ValidationErrors, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialogActions, MatDialogContent, MatDialogTitle } from '@angular/material/dialog';
import { fileInfoBaseDto, folder, file } from 'ispace.core.main';
import { RenameCmpComponent } from '../rename-cmp/rename-cmp.component';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';

@Component({
  selector: 'app-create-symbolic-link-cmp',
  standalone: true,
  imports: [    MatFormFieldModule, 
      MatButtonModule,
      MatDialogTitle,
      MatDialogContent,
      MatDialogActions, 
      CommonModule,
      FormsModule,
      MatInputModule, 
      ReactiveFormsModule],
  templateUrl: './create-symbolic-link-cmp.component.html',
  styleUrl: './create-symbolic-link-cmp.component.scss'
})
export class CreateSymbolicLinkCmpComponent {

  
  constructor( public dialogRef: MatDialogRef<RenameCmpComponent>,
    @Inject(MAT_DIALOG_DATA) public data: fileInfoBaseDto,) {
    }
  
  nameFormControl = new FormControl<string>('', {
        validators: [
          Validators.required, 
        ]
      });
  pathFormControl = new FormControl<string>('', {
        validators: [
          Validators.required,
        ]
      });

  onYesClick() { 
      if (this.nameFormControl.valid) { 
        file.createSymbolicLink(this.data.path!, this.nameFormControl.value!, this.pathFormControl.value!).subscribe({
          next: () => {
            this.dialogRef.close(true);
          },error: (err) => {
            console.error(err);
            this.dialogRef.close(false);
          }
        });
      }  
  }

  onNoClick(): void {
    this.dialogRef.close(false);
  }
}
 
